﻿using System;
using System.Text;
using System.Web;
using Clipping.Infrastructure.Interfaces;

namespace Clipping.SearchUrlConstructors
{
	public class GoogleWebUrlConstructor : ISearchUrlConstruct
	{
		public Uri ConstructUrl(Infrastructure.Models.SearchObject searchObj)
		{
			//Contract.Requires(searchObj != null);
			string url = string.Format("http://www.google.com.hk/search?num=20&complete=1&hl=zh-CN&newwindow=1&as_qdr=all&q={0}&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=f", HttpUtility.UrlEncode(searchObj.Keyword, Encoding.UTF8));
			if (searchObj.SearchType == Infrastructure.Models.SearchType.SearchInTitle)
				url = url + "&as_occt=title";
			return new Uri(url);
		}

		public Uri ConstructAbsoluteUrl(Uri baseUri, string url)
		{
			if (!string.IsNullOrEmpty(url))
				url = url.Replace("&amp;", "&");
			return UriHelper.ConstructAbsoluteUrl(baseUri, url);
		}
	}
}
